//
//  CCUIButton.m
//  CCFC_IPHONE
//
//  Created by  xuchen(陈旭)， xichen(陈曦)， qq：511272827 on 10-10-31.
//  Copyright 2010 cc_team. All rights reserved.
//

#include "CCUIButton.h"

#include "CCAll.h"

#ifdef	CPP_MACRO
namespace CC
{

	Button::Button(
				   NSString *normalTitle, 
				   NSString *normalImg,
				   NSString *pressedImg,
				   SEL clickAction,
				   id delegate
				   )
	{
		button = CREATE_CUSTOM_BUTTON;
		
		UIImage *buttonImage = CREATE_UIIMAGE(normalImg);
		SET_BUTTON_BG_IMG(button, buttonImage, UIControlStateNormal);
		
		buttonImage = CREATE_UIIMAGE(pressedImg);
		SET_BUTTON_BG_IMG(button, buttonImage, UIControlStateHighlighted);
		
		BUTTON_ADD_TARGET(button, delegate, clickAction, UIControlEventTouchUpInside); 
		SET_BUTTON_TITLE(button, normalTitle);
		
		[button retain];
	}
	
	Button::Button(
				   NSString *normalTitle, 
				   SEL clickAction,
				   id delegate
				   )
	{
		button = [UIButton buttonWithType:UIButtonTypeRoundedRect];	//通用的白色圆角按钮
		
		BUTTON_ADD_TARGET(button, delegate, clickAction, UIControlEventTouchUpInside); 
		SET_BUTTON_TITLE(button, normalTitle);	//设置标题
		
		[button retain];
	}
	
	Button::~Button()
	{
		RELEASE(button);
	}
	
	UIButton *Button::getButton()
	{
		return button;
	}
	
	void Button::setFrame(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
	{
		assert(button != nil);
		
		SET_VIEW_X(button, x);
		SET_VIEW_Y(button, y);
		SET_VIEW_WIDTH(button, width);
		SET_VIEW_HEIGHT(button, height);
	}
}
#endif	//CPP_MACRO
